#  Perl Audio Converter
#
#  Copyright (C) 2005-2008 Philip Lyons
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

PACKAGE_NAME    = @PACKAGE_NAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
INSTALL_AMAROK  = @INSTALL_AMAROK@
INSTALL_KONQ    = @INSTALL_KONQ@
INSTALL_DOLP    = @INSTALL_DOLP@

ACLOCAL_M4 = ./aclocal.m4

#
# Modules & Documentation
#

LANG_MODS = po/*
DOCS = README AUTHORS COPYING INSTALL TODO ChangeLog
EXTRAS = extra/*

#
# Plugin directories
#

AMAROKDIR = plugins/amarok
DOLPDIR   = plugins/dolphin
KONQDIR   = plugins/konqueror

#
# Default KDE directory
#

DESTDIR = 
KDEDIR  = /usr

#
# Compiler tools definitions...
#

POD2MAN = @POD2MAN@
POD2HTML = @POD2HTML@
GZIP = @GZIP@
RM = @RM@ -f
SHELL = /bin/sh
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

#
# Configured directories...
#

prefix      =  @prefix@
exec_prefix =  @exec_prefix@
bindir      =  @bindir@
datarootdir =  @datarootdir@
includedir  =  @includedir@
libdir      =  @libdir@
mandir      =  @mandir@
docdir      =  @docdir@

# Explicit rules
.PHONY: all install uninstall clean distclean

all: pacpl.1

pacpl.1: pacpl
	$(POD2MAN) $< |	$(GZIP) -9 >$@.gz

install: main pacpl-plugins

main:
	$(INSTALL) -d $(DESTDIR)$(bindir)
	$(INSTALL) -d $(DESTDIR)/etc/pacpl
	$(INSTALL) -d $(DESTDIR)/etc/pacpl/po
	$(INSTALL) -d $(DESTDIR)/etc/pacpl/modules
	$(INSTALL) -d $(DESTDIR)$(mandir)/man1
	$(INSTALL) -d $(DESTDIR)$(prefix)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
	$(INSTALL) -d $(DESTDIR)$(prefix)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)/extra

	$(INSTALL) pacpl -t $(DESTDIR)$(bindir)
	$(INSTALL_DATA) pacpl.conf -t $(DESTDIR)/etc/pacpl
	$(INSTALL_DATA) codecs.conf -t $(DESTDIR)/etc/pacpl
	$(INSTALL_DATA) $(LANG_MODS) -t $(DESTDIR)/etc/pacpl/po
	$(INSTALL_DATA) extra/sample.m -t $(DESTDIR)/etc/pacpl/modules
	$(INSTALL_DATA) pacpl.1.gz $(DESTDIR)$(mandir)/man1
	$(INSTALL_DATA) $(DOCS) -t $(DESTDIR)$(prefix)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
	$(INSTALL_DATA) $(EXTRAS) -t $(DESTDIR)$(prefix)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)/extra

pacpl-plugins:
ifeq '$(INSTALL_KONQ)' 'yes'
	$(INSTALL) -d $(DESTDIR)$(KDEDIR)/share/apps/konqueror/servicemenus
	$(INSTALL) -d $(DESTDIR)$(KDEDIR)/share/mimelnk/audio

	$(INSTALL_DATA) $(KONQDIR)/pacpl.desktop -t $(DESTDIR)$(KDEDIR)/share/apps/konqueror/servicemenus
	$(INSTALL_DATA) $(KONQDIR)/mimes/* -t $(DESTDIR)$(KDEDIR)/share/mimelnk/audio/ 
endif

ifeq '$(INSTALL_DOLP)' 'yes'
	$(INSTALL) -d $(DESTDIR)$(KDEDIR)/share/apps/dolphin/servicemenus
	$(INSTALL_DATA) $(DOLPDIR)/pacpl.desktop -t $(DESTDIR)$(KDEDIR)/share/apps/dolphin/servicemenus
endif

ifeq '$(INSTALL_AMAROK)' 'yes'
	$(INSTALL) -d $(DESTDIR)$(KDEDIR)/share/apps/amarok/scripts/pacx
	$(INSTALL) $(AMAROKDIR)/pacx -t $(DESTDIR)$(KDEDIR)/share/apps/amarok/scripts/pacx
endif

clean:
	$(RM) pacpl.1.gz

distclean:
	$(RM) pacpl.1.gz
	$(RM) po/*~
	$(RM) plugins/*~
	$(RM) plugins/dolphin/*~
	$(RM) plugins/konqueror/*~
	$(RM) plugins/konqueror/mimes/*~
	$(RM) plugins/amarok/*~
	$(RM) config.log
	$(RM) config.status
	$(RM) Makefile
	$(RM) *~

uninstall:
	$(RM) $(bindir)/pacpl
	$(RM) -r /etc/pacpl/
	$(RM) $(mandir)/man1/pacpl.1.gz
	$(RM) -r $(prefix)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)

ifeq '$(INSTALL_KONQ)' 'yes'
	$(RM) $(KDEDIR)/share/apps/konqueror/servicemenus/pacpl.desktop
endif

ifeq '$(INSTALL_DOLP)' 'yes'
	$(RM) $(KDEDIR)/share/apps/dolphin/servicemenus/pacpl.desktop
endif

ifeq '$(INSTALL_AMAROK)' 'yes'
	$(RM) $(KDEDIR)/share/apps/amarok/scripts/pacx/pacx
	$(RM) -r $(KDEDIR)/share/apps/amarok/scripts/pacx
endif
